package com.weibo4j.api;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;

import com.weibo4j.api.util.HttpClientUtil;

public class DefaultWeiboClient implements WeiboClient{
	
	private HttpClient client = HttpClientUtil.getHttpClient();

	@Override
	public <T extends WeiboResponse> T execute(WeiboRequest<T> req) throws ApiException {
		try {
			HttpResponse resp = client.execute(req.generateRequest());
			T weiboResponse = req.responseType().newInstance();
			weiboResponse.setHttpResponse(resp);
			return weiboResponse;
		} catch (Throwable e) {
			throw new ApiException(e);
		} 
	}

}
